This is my code
User.init({
email: {
type: DataTypes.STRING,
validate: {
isEmail: {
args: true,
msg: "Invalid email format"
},
notEmpty: {
args: true,
msg: 'Cannot be blank'
},
unique: {
args: true,
msg: "Email must be unique"
}
},
}
I check using Postman. I register as a new user but the "Invalid validator function: unique" shows up instead of being registered.
The unique option is not a part of the validate option, it should be outside on the same level as validate:
User.init({
email: {
type: DataTypes.STRING,
unique: {
args: true,
msg: "Email must be unique"
},
validate: {
isEmail: {
args: true,
msg: "Invalid email format"
},
notEmpty: {
args: true,
msg: 'Cannot be blank'
}
}
}